package sitedao

import (
	"errors"
	"hft/Database/admin"
	"hft/e"
	"hft/global"

	"gorm.io/gorm"
)

// 设置当前的站点的配置
func SetCityConfig(region int, db *gorm.DB) (err error) {

	var CitySetting = &admin.CitySetting{
		LouPanClueScore: uint(global.OC_CONFIG.CitySetting.LouScore),
		CommonClueScore: uint(global.OC_CONFIG.CitySetting.CommonScore),
		PerMonthScore:   uint(global.OC_CONFIG.CitySetting.PerMonthScore),
		LimitScore:      uint(global.OC_CONFIG.CitySetting.BrokerScoreLimit),
		Residential:     global.OC_CONFIG.CitySetting.Residential,
		Commercial:      global.OC_CONFIG.CitySetting.Commercial,
		GongJiJIn:       global.OC_CONFIG.CitySetting.GongJiJIn,
		Region:          region,
		LevelA:          global.OC_CONFIG.CitySetting.LevelA,
		LevelB:          global.OC_CONFIG.CitySetting.LevelB,
		LevelC:          global.OC_CONFIG.CitySetting.LevelC,
		LevelD:          global.OC_CONFIG.CitySetting.LevelProtect,
		// LevelE:          global.OC_CONFIG.CitySetting.LevelE,
		// LevelF:          global.OC_CONFIG.CitySetting.LevelProtect,
	}
	res := db.Where("region = ?", region).FirstOrCreate(&CitySetting)
	if res.Error != nil {
		return errors.New(e.ErrorInfo)
	}

	return nil
}
